﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace lcs.Web.SupplyPlanSectionQRC
{
    public partial class SetProductionOrder : System.Web.UI.Page
    {
        Maticsoft.BLL.supplyPlanOrderQRC sm = new Maticsoft.BLL.supplyPlanOrderQRC();
        lcs.BLL.mobileSendInfo mm = new BLL.mobileSendInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["supplyPlanId"]))
                {
                    this.lbl_supplyPlanId.Text = Request["supplyPlanId"];
                    Bind(Request["supplyPlanId"]);
                }
            }
        }

        private void Bind(string supplyPlanId)
        {
            DataSet ds = sm.GetListByView(" supplyPlanId = " + supplyPlanId);
            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
        }

        protected void btn_sel_Click(object sender, EventArgs e)
        {
            //Maticsoft.Model.supplyPlanOrderQRC s = new Maticsoft.Model.supplyPlanOrderQRC();

            //s.sectionname = this.txt_sectionname.Text;
            //s.sectionorder = int.Parse(this.txt_sectionorder.Text);
            //s.supplyPlanId = int.Parse(lbl_supplyPlanId.Text);

            //sm.Add(s);

            //Bind(s.supplyPlanId.ToString());

            lcs.Model.mobileSendInfo m = new Model.mobileSendInfo();
           
            try
            {
                m.sectionid = int.Parse(this.txt_sectionorder.Text);
                m.supplyPlanId = int.Parse(lbl_supplyPlanId.Text);
                m.sectionname = this.txt_sectionname.Text;

                if (mm.Add(m) > 0)
                {
                    Bind(m.supplyPlanId.ToString());
                }
                else
                {
                    Maticsoft.Common.MessageBox.Show(this, "添加失败！");
                }

            }
            catch (Exception)
            {

                Maticsoft.Common.MessageBox.Show(this, "生产步骤请输入正整数！");
            }
           

        }


        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "lbn_del")
            {
                string KeyId = e.CommandArgument.ToString();
                string supplyPlaneId = this.lbl_supplyPlanId.Text;

                //if (sm.Delete(int.Parse(sectionid)))
                //{
                //    Bind(this.lbl_supplyPlanId.Text);
                //}


                //List<lcs.Model.mobileSendInfo> lm = mm.GetModelList(" and supplyPlanId="+ supplyPlaneId + " and sectionid="+ sectionid + " ");

                //if (lm.Count == 1)
                //{
                //    lcs.Model.mobileSendInfo m = lm[0];

                //    if (mm.Delete(m.KeyId))
                //    {
                //        Bind(this.lbl_supplyPlanId.Text);
                //    }
                //}

                //lcs.Model.mobileSendInfo m = mm.GetModel(int.Parse(KeyId));

                if (mm.Delete(int.Parse(KeyId)))
                {
                    Bind(this.lbl_supplyPlanId.Text);
                }
            }
            if (e.CommandName == "lbn_add")
            {
                string sectionid = e.CommandArgument.ToString();
                string supplyPlaneId = this.lbl_supplyPlanId.Text;

                string id = sectionid + "-" + supplyPlaneId;

                //Response.Redirect("../PrintQCR.aspx?id=" + id + "&type=productionOrder");

                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>showQRC('"+id+"')</script>");

            }


        }

       
 
    }
}